package ca.seia.comp6521.a2;

import java.io.File;
import java.io.FileNotFoundException;

import ca.seia.comp6521.a2.itemsetalgorithms.Apriori;

import com.javabi.sizeof.MemoryUtil;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("Comp6521 Project 2");
		File inputFile = null;
		String filePath = null;
		int percentage = -1;
		if (args !=null && args.length == 2) {
			try {
				filePath = args[0];
				inputFile = new File(filePath);
				
				if(!inputFile.isFile()) {
					System.err.println("Please enter a valid file");
					return;
				}
				percentage = Integer.valueOf(args[1]);
				Apriori apriori = new Apriori(inputFile, percentage);
				System.out.println("Size of free memory " + MemoryUtil.free());
				System.out.println("Size of max memory " + MemoryUtil.max());
				long startTime = System.currentTimeMillis();
				apriori.getFrequentItemSets();
				//apriori.getFrequentItemSetsPCY();
				System.out.println("total Time = " + (System.currentTimeMillis() - startTime) + " ms");
			} catch (NumberFormatException ex) {
				System.err.println("Please input a valid number");
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		} else {
			System.err.println("Usage: <filePath> <percentageValue>");
		}
	}

}
